package com.jming.jike.enums;

import com.jming.jike.common.BusinessException;

/**
 * 订单状态枚举
 *
 * @author jinming.zhang
 * @version 0.0.1
 * @date 2022/04/29
 */
public enum OrdersStatusEnum {

    /**
     * 待付款
     */
    WAIT_PAY(1, "待付款"),

    /**
     * 待派送
     */
    WAIT_DELIVERY(2, "待派送"),

    /**
     * 已派送
     */
    ALREADY_DELIVERY(3, "已派送"),

    /**
     * 已完成
     */
    ALREADY_FINISH(4, "已完成"),

    /**
     * 已取消
     */
    ALREADY_CANCEL(5, "已取消");

    private final Integer code;
    private final String desc;

    OrdersStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 检查状态
     *
     * @param code
     * @Author jinming.zhang
     * @Date 2022/4/22
     */
    public static void checkStatus(Integer code) {

        for (OrdersStatusEnum ordersStatusEnum : OrdersStatusEnum.values()) {
            if (ordersStatusEnum.code.equals(code)) {
                return;
            }
        }

        throw new BusinessException("状态不正确!");
    }

}
